From ad2d0860f3055836c1e3b988ce2ed5d59e616b48 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Wed, 9 Apr 2008 13:31:19 +0100 Subject: [PATCH] xenstore: merge xenstore-ls into the multicall binary. This is done separately from moving the other utilities into the mutlicall since ls is slightly different and was already separate. Signed-off-by: Ian Campbell --- tools/xenstore/Makefile | 12 +- tools/xenstore/xenstore_client.c | 183 +++++++++++++++++++++++++++++-- tools/xenstore/xsls.c | 171 ----------------------------- 3 files changed, 176 insertions(+), 190 deletions(-) delete mode 100644 tools/xenstore/xsls.c diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile index 6bfb1b6b6b..9b7e9e89c6 100644 --- a/tools/xenstore/Makefile +++ b/tools/xenstore/Makefile @@ -13,7 +13,7 @@ CFLAGS += -Wp,-MD,.$(@F).d DEP = .*.d CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm xenstore-chmod -CLIENTS += xenstore-write +CLIENTS += xenstore-write xenstore-ls XENSTORED_OBJS = xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o tdb.o hashtable.o @@ -27,14 +27,14 @@ ifneq ($(XENSTORE_STATIC_CLIENTS),y) LIBXENSTORE := libxenstore.so else LIBXENSTORE := libxenstore.a -xenstore xenstore-control xenstore-ls: CFLAGS += -static +xenstore xenstore-control: CFLAGS += -static endif .PHONY: all all: libxenstore.so libxenstore.a xenstored clients xs_tdb_dump .PHONY: clients -clients: xenstore $(CLIENTS) xenstore-control xenstore-ls +clients: xenstore $(CLIENTS) xenstore-control ifeq ($(CONFIG_SunOS),y) xenstored_probes.h: xenstored_probes.d @@ -60,9 +60,6 @@ xenstore: xenstore_client.o $(LIBXENSTORE) xenstore-control: xenstore_control.o $(LIBXENSTORE) $(CC) $(CFLAGS) $(LDFLAGS) $< -L. -lxenstore $(SOCKET_LIBS) -o $@ -xenstore-ls: xsls.o $(LIBXENSTORE) - $(CC) $(CFLAGS) $(LDFLAGS) $< -L. -lxenstore $(SOCKET_LIBS) -o $@ - xs_tdb_dump: xs_tdb_dump.o utils.o tdb.o talloc.o $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ @@ -83,7 +80,7 @@ libxenstore.a: xs.o xs_lib.o clean: rm -f *.a *.o *.opic *.so* xenstored_probes.h rm -f xenstored xs_random xs_stress xs_crashme - rm -f xs_tdb_dump xenstore-control xenstore-ls + rm -f xs_tdb_dump xenstore-control rm -f xenstore $(CLIENTS) $(RM) $(DEP) @@ -108,7 +105,6 @@ install: all set -e ; for c in $(CLIENTS) ; do \ ln -f $(DESTDIR)/usr/bin/xenstore $(DESTDIR)/usr/bin/$${c} ; \ done - $(INSTALL_PROG) xenstore-ls $(DESTDIR)$(BINDIR) $(INSTALL_DIR) $(DESTDIR)$(LIBDIR) $(INSTALL_PROG) libxenstore.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR) ln -sf libxenstore.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)/libxenstore.so.$(MAJOR) diff --git a/tools/xenstore/xenstore_client.c b/tools/xenstore/xenstore_client.c index 422fc231a4..dabf4f72a9 100644 --- a/tools/xenstore/xenstore_client.c +++ b/tools/xenstore/xenstore_client.c @@ -16,8 +16,12 @@ #include #include #include +#include +#include #include +#include + #define PATH_SEP '/' #define MAX_PATH_LEN 256 @@ -28,6 +32,7 @@ enum mode { MODE_chmod, MODE_exists, MODE_list, + MODE_ls, MODE_read, MODE_rm, MODE_write, @@ -84,6 +89,9 @@ usage(enum mode mode, int incl_mode, const char *progname) case MODE_list: mstr = mstr ? : incl_mode ? "list " : ""; errx(1, "Usage: %s %s[-h] [-s] key [...]", progname, mstr); + case MODE_ls: + mstr = mstr ? : incl_mode ? "ls " : ""; + errx(1, "Usage: %s %s[-h] [-s] [path]", progname, mstr); case MODE_chmod: mstr = incl_mode ? "chmod " : ""; errx(1, "Usage: %s %s[-h] [-s] key ", progname, mstr); @@ -103,6 +111,111 @@ do_rm(char *path, struct xs_handle *xsh, xs_transaction_t xth) } } +#define STRING_MAX XENSTORE_ABS_PATH_MAX+1024 +static int max_width = 80; +static int desired_width = 60; +static int show_whole_path = 0; + +#define TAG " = \"...\"" +#define TAG_LEN strlen(TAG) + +#define MIN(a, b) (((a) < (b))? (a) : (b)) + +void do_ls(struct xs_handle *h, char *path, int cur_depth, int show_perms) +{ + static struct expanding_buffer ebuf; + char **e; + char newpath[STRING_MAX], *val; + int newpath_len; + int i; + unsigned int num, len; + + e = xs_directory(h, XBT_NULL, path, &num); + if (e == NULL) + err(1, "xs_directory (%s)", path); + + for (i = 0; i 2; break; + case MODE_ls: + transaction = 0; + break; default: transaction = 1; break; } + if ( mode == MODE_ls ) + { + memset(&ws, 0, sizeof(ws)); + ret = ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws); + if (!ret) + max_width = ws.ws_col - 2; + } + xsh = socket ? xs_daemon_open() : xs_domain_open(); if (xsh == NULL) err(1, socket ? "xs_daemon_open" : "xs_domain_open"); diff --git a/tools/xenstore/xsls.c b/tools/xenstore/xsls.c deleted file mode 100644 index 337e87cc5b..0000000000 --- a/tools/xenstore/xsls.c +++ /dev/null @@ -1,171 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define STRING_MAX XENSTORE_ABS_PATH_MAX+1024 -static int max_width = 80; -static int desired_width = 60; -static int show_whole_path = 0; - -#define TAG " = \"...\"" -#define TAG_LEN strlen(TAG) - -#define MIN(a, b) (((a) < (b))? (a) : (b)) - -void print_dir(struct xs_handle *h, char *path, int cur_depth, int show_perms) -{ - static struct expanding_buffer ebuf; - char **e; - char newpath[STRING_MAX], *val; - int newpath_len; - int i; - unsigned int num, len; - - e = xs_directory(h, XBT_NULL, path, &num); - if (e == NULL) - err(1, "xs_directory (%s)", path); - - for (i = 0; i